<template>
  <div>
    <!--工具类-->

    <Row style="text-align: left" v-model="status.modalSearch.isShow">
      <i-col span="24">
        <div>
          <div style="text-align: right;" class="order_btns">
            <Button type="info" icon="ios-download-outline" @click="exportOrderTurnover" v-has=tRole.ORDER_1_109>导出订单流水</Button>
            <Button type="info" icon="ios-download-outline" @click="exportReport" v-has=tRole.ORDER_1_102>导出报表</Button>
            <Button type="info" @click="showExportTransferExcel" icon="ios-download-outline" v-has=tRole.ORDER_1_103>物流对接单</Button>
<!--            <Button type="info" @click="exportMiaozhangSale" icon="ios-download-outline" v-has=tRole.ORDER_1_106>秒帐销售单</Button>-->
            <Button type="info" @click="exportPurchaseOrders" icon="ios-download-outline" v-has=tRole.ORDER_1_107>导出采购单</Button>
            <Button type="info" @click="batchExportOrdersBlank" icon="ios-download-outline" v-has=tRole.ORDER_1_104>导出配货单</Button>
            <Button type="info" @click="batchExportOrdersInvoice" icon="ios-download-outline" v-has=tRole.ORDER_1_105>导出发货单</Button>
            <Button type="info" @click="batchExportProductCodes" icon="ios-download-outline" v-has=tRole.ORDER_1_108>导出产品编码</Button>
            <Button type="info" @click="batchExportTradeData" icon="ios-download-outline" v-has=tRole.ORDER_1_115>导出跨境认证数据</Button>
            <Button type="primary" @click="showConfirmOrders" icon="md-checkmark" v-has=tRole.ORDER_1_111>订单确认</Button>
            <Button type="primary" @click="showPrepareModal" icon="ios-cart" v-has=tRole.ORDER_1_112>订单备货</Button>
            <Button type="primary" @click="showStockOutModal" icon="md-send" v-has=tRole.ORDER_1_113>订单出库</Button>
            <Button type="primary" @click="showImportantNoteModal" icon="md-create" v-has=tRole.ORDER_1_110>修改重要说明</Button>
            <Button type="primary" @click="removeImportantNote" icon="md-close" v-has=tRole.ORDER_1_110>清除重要说明</Button>
          </div>
          <divider></divider>
          <div v-has=tRole.ORDER_1_101 class="y_query_right">
            <Select placeholder="请选择订单状态" v-model="params.orderState" class="y_condition" clearable style="text-align: left;">
              <Option value="">全部状态</Option>
              <Option v-for="item in orderStateDict" :value="item.value" :key="item.value">{{ item.name }}</Option>
            </Select>
            <Input v-model.trim="params.orderSerialNumber" placeholder="订单流水号" clearable class="y_condition"></Input>
            <Input v-model.trim="params.userName" placeholder="请输入用户名" clearable class="y_condition"></Input>
            <Input v-model.trim="params.userEmail" placeholder="用户邮箱" clearable class="y_condition"></Input>
            <Input v-model.trim="params.waybill" placeholder="请输入物流单号" clearable class="y_condition"></Input>
            <DatePicker type="datetime" v-model="params.startTime" format="yyyy-MM-dd HH:mm" class="y_condition" placeholder="选择起始时间"></DatePicker>-&nbsp;&nbsp;&nbsp;
            <DatePicker type="datetime" v-model="params.endTime" format="yyyy-MM-dd HH:mm" class="y_condition" placeholder="选择结束时间"></DatePicker>
            <Button type="primary" class="y_condition" icon="ios-search" @click="search">查询</Button>
          </div>
        </div>
      </i-col>
    </Row>

    <!--表格和分页-->
<!--    <Table stripe border :columns="tableTitles" :data="orderList" ref="orderList"
           class="table_css" @on-selection-change="orderSelectedChanged" @on-sort-change="orderSort"
           no-data-text="暂无数据"></Table>-->

    <List style="border-top: 1px solid #e8eaec;border-bottom: 1px solid #e8eaec;margin-top: 1rem;margin-bottom: 1rem;">
      <ListItem style="display: flex;align-items: flex-start;margin-left: 1rem;">
        <Checkbox v-model="isCheckedAllMessage" @on-change="handleCheckAll">全选</Checkbox>
        <ListSort sort-label="付款时间" :sort-by="params.orderBy" sort-value="o.chekout_time" @change="orderSort"></ListSort>
      </ListItem>
      <template v-if="orderList.length == 0">
        <ListItem><div style="width: 100%; text-align: center;">暂无数据</div></ListItem>
      </template>
      <CheckboxGroup v-model="params.selectedOrders" @on-change="checkChange">
        <list-item class="list_item" v-for="(item,index) in orderList">
        <div style="width:100%;"  >
          <Row type="flex" justify="space-between" align="middle">
            <i-col :xs="2" :sm="2" :md="1" style="padding:0.25rem 0;">
              <Checkbox :disabled="item._disabled" :label="item" :value="index">{{ check }}</Checkbox>
            </i-col>
            <i-col :xs="22" :sm="22" :md="23" style="text-align: left;" >
              <div style="width:100%;padding:0.25rem 0;">
                <KeyValueView>#{{index+1}}</KeyValueView>
                <KeyValueView v-if="$authority('ORDER-1-205')"  title="订单流水号" >
                  <a @click="showOrderDetail(item.id)" target="_blank">{{item.serialNumber}}</a>
                </KeyValueView>
                <KeyValueView v-else title="订单流水号">{{item.serialNumber}}</KeyValueView>
                <KeyValueView v-if="$authority('ORDER-1-203')" title="金额">${{item.actualPayment}}</KeyValueView>
                <KeyValueView title="订单状态">{{orderStateDict.find(i => i.value == item.state)==null?'':orderStateDict.find(i => i.value == item.state).name}}</KeyValueView>
                <KeyValueView v-if="$authority('ORDER-1-222')" title="邀请码">{{isEmpty(item.userInviteCode)?'无':item.userInviteCode}}</KeyValueView>
                <Tag v-if="item.firstOrder===1" color="green">首单</Tag>
                <Tag v-if="item.firstOrder===2">复购单</Tag>
              </div>
              <div style="width:100%;padding:0.25rem 0;">


<!--                <KeyValueView v-if="item.firstOrder==1" title="首单"><tag color="red">首单</tag></KeyValueView>-->
<!--                <KeyValueView v-else-if="item.firstOrder==2" title="首单"><tag color="green">复购</tag></KeyValueView>-->
<!--                <KeyValueView v-else title="首单"></KeyValueView>-->
<!--                -->
                <span v-if="$authority('ORDER-1-201')">
                  <KeyValueView v-if="$authority('ORDER-1-218')" title="用户">
                    <a style="padding:6px;font-size:13px" @click="showUserContactInfo(item)">{{isEmpty(item.encodeName)?item.userName:item.encodeName}}</a>
                  </KeyValueView>
                  <KeyValueView v-else title="用户">
                    {{isEmpty(item.encodeName)?item.userName:item.encodeName}}
                  </KeyValueView>
                </span>
                <KeyValueView v-if="$authority('ORDER-1-202')" title="国家">{{item.countryName}}</KeyValueView>

                <KeyValueView title="设备">{{getDeviceName(item.deviceType)}}</KeyValueView>
                <KeyValueView title="下单时间" >{{ $tiyBJTime(item.createtime) }}</KeyValueView>
                <KeyValueView title="付款时间" >{{ $tiyBJTime(item.checkoutTime) }}</KeyValueView>
              </div>
            </i-col>
          </Row>
          <Row v-if="!isEmpty(item.note)" type="flex" justify="space-between" >
            <i-col :xs="2" :sm="2" :md="1" style="padding:0.25rem 0;">
            </i-col>
            <i-col :xs="22" :sm="22" :md="23" align="left" style="padding:0.25rem 0;">
              <KeyValueView title="用户备注">{{item.note}}</KeyValueView>
            </i-col>
          </Row>
          <Row v-if="!isEmpty(item.importantNote)" type="flex" justify="space-between" >
            <i-col :xs="2" :sm="2" :md="1" style="padding:0.25rem 0;">
            </i-col>
            <i-col :xs="22" :sm="22" :md="23" align="left" style="padding:0.25rem 0;">
              <KeyValueView title="重要说明">{{item.importantNote}}</KeyValueView>
            </i-col>
          </Row>
          <Row v-if="!isEmpty(item.innerNoteText)" type="flex" justify="space-between" >
            <i-col :xs="2" :sm="2" :md="1" style="padding:0.25rem 0;">
            </i-col>
            <i-col :xs="22" :sm="22" :md="23" align="left" style="padding:0.25rem 0;">
              <KeyValueView title="运营备注">
                <a style="padding:6px;font-size:14px" @click="showInnerNote(item.id)">查看</a>
              </KeyValueView>
            </i-col>
          </Row>
        </div>
      </list-item>
      </CheckboxGroup>
    </List>
    <div style="float: right;">
      <Page :total="tPage.total" :page-size="tPage.stepNumber" :current="tPage.currentPage" @on-change="changePage"
            @on-page-size-change="sizeChange" :page-size-opts="[40,60,80,120,240]"
            show-sizer show-elevator/>
    </div>

    <!--确认订单 -->
    <Modal v-model="status.modalConfirmOrderShow" width="80%"
           draggable title="订单款项确认" @on-ok="confirmOrders()">
      <Row><span class="key">确认款项是否已到帐！</span></Row>
      <Row>
        <RadioGroup v-model="params.isConfirmed">
          <Radio :label=1 >已到帐</Radio>
          <Radio :label=0>未到帐</Radio>
        </RadioGroup>
      </Row>
    </Modal>

    <!--确认弹出框-->
    <Modal
      v-model="status.modalAction.isShow"
      :title="status.modalAction.title"
      :loading="status.modalAction.isLoading"
      @on-ok="actionOk">
      <br>
      <p>{{status.modalAction.content}}?</p>
      <br>
    </Modal>
    <a-OrderDetail  ref="orderDetail" @hideDetail="hideDetail()" :orderId="orderId" :detailShow="isShowDetail" v-show="isShowDetail" > </a-OrderDetail>

    <!--查看用户详细联系信息弹出框-->
    <Modal v-model="status.modalUserContactInfo.isShow" title="用户联系方式"
           :styles="{align:'center',width:'60%',padding:'2rem'}" :scrollable=true >
<!--      <Row>-->
<!--        <i-col span="10">-->
<!--          <div> <span class="key">国家电话代码 :</span> {{status.modalUserContactInfo.info.phoneCode}}</div>-->
<!--        </i-col>-->
<!--        <i-col span="10">-->
<!--          <div><span class="key">联系电话 :</span> {{status.modalUserContactInfo.info.mobile}}</div>-->
<!--        </i-col>-->
<!--      </Row>-->
<!--      <Row>-->
<!--        <i-col span="10">-->
<!--          <div> <span class="key">Facebook :</span> {{status.modalUserContactInfo.info.facebook}}</div>-->
<!--        </i-col>-->
<!--        <i-col span="10">-->
<!--          <div><span class="key">Instagram :</span> {{status.modalUserContactInfo.info.instagram}}</div>-->
<!--        </i-col>-->
<!--      </Row>-->
      <Row>
        <i-col span="10">
          <div> <span class="key">联系邮箱 :</span> {{$tiyHideEmail(status.modalUserContactInfo.info.email)}}
            <Button size="small" type="info" ghost style="" @click="copyEmail(status.modalUserContactInfo.info.email)" icon="md-copy" v-has=tRole.ORDER_1_221 >
              copy
          </Button>

          </div>

        </i-col>
<!--        <i-col span="14">-->
<!--          <div><span class="key">独立站 :</span><a v-if="status.modalUserContactInfo.info.web != null" target='_blank' :href="status.modalUserContactInfo.info.web">{{status.modalUserContactInfo.info.web}}</a> </div>-->
<!--        </i-col>-->
      </Row>
      <Row style="margin-top: 5px">
        <i-col span="8">
          <Button type="info" style="" @click="showEmail" icon="md-mail"
                  v-has=tRole.ORDER_1_221 >发送邮件
          </Button>
        </i-col>
      </Row>
      <div slot="footer">
        <Button type="primary" @click="status.modalUserContactInfo.isShow = false;">确定</Button>
      </div>
    </Modal>

    <!-- 发送邮件 -->
    <Modal
      v-model="showEmailState.isShowing"
      title=""
      :mask-closable="false"
      :styles="{top: '20px',bottom:'20px',width:'80%'}">
      <send-email v-bind:receiveUser="showEmailState.selectedUsers" v-bind:isRefresh="showEmailState.isShowing"
                       v-on:listenSendEmailEvent="sendSuccess" :is-send="false"  ref="SendEmail"></send-email>
      <div slot="footer"></div>
    </Modal>

    <!-- 运营备注 -->
    <Modal
      v-model="status.modalInnerNote.isShow"
      title="运营备注"
      width="65"
      :styles="{align:'center'}"
      :scrollable=true>
      <List v-if="tData.innerNoteList.length>0" border size="small">
        <ListItem v-for="(item,index) in tData.innerNoteList" >
          <row style="width:100%;">
            <i-col  span="24">
              <span style="font-weight: bold;">{{index+1}}.</span><span > {{item.content}}</span>
              <span style="float:right"><tag color="red">{{item.employeeName}}</tag> {{$tiyBJTime(item.createtime)}}</span>
            </i-col>
          </row>

        </ListItem>
      </List>
    </Modal>

    <Modal v-model="status.modalExportTransferExcel.isShow" title="物流对接单" @on-ok="exportTransferExcel()" :closable="false" :mask-closable="false">
      <Row>
        <span class="key">选择需要导出的物流对接单</span>
      </Row>
      <Row>
        <RadioGroup v-model="params.transferExcelType" vertical>
          <Radio label="1">
            <span>W物流对接单</span>
          </Radio>
<!--          <Radio label="2">-->
<!--            <span>EMS物流对接单</span>-->
<!--          </Radio>-->
          <Radio label="3">
            <span>DHL物流对接单</span>
          </Radio>
        </RadioGroup>
      </Row>
    </Modal>

    <!-- 修改重要说明对话框 -->
    <Modal v-model="status.modalImportantNote.isShow" title="修改重要说明" :closable="false" :mask-closable="false" label-c>
      <Form  label-colon :label-width="80">
        <div style="color: #ff9900; margin-bottom: 10px; margin-left: 10px;">
          <Icon type="md-warning" size="20"></Icon>订单原来的重要说明会被覆盖
        </div>
        <FormItem label="重要说明" prop="importantNote">
          <Input type="textarea" v-model.trim="params.modifyImportantNote.importantNote" :rows="5" style="width: 90%;"/>
          <Icon type="ios-close-circle" @click="clearImportantNote()" style="position: absolute; margin-left: -18px; margin-top: 5px;"/>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button @click="status.modalImportantNote.isShow=false">取消</Button>
        <Button type="primary" @click="modifyImportantNote()">保存</Button>
      </div>
    </Modal>

    <!--确认弹出框-->
    <Modal
      v-model="status.modalConfirm.isShow"
      :title="status.modalConfirm.title"
      :isLoading="status.modalConfirm.isLoading"
      @on-ok="status.modalConfirm.onOk()"
    >
      <br>
      <p>{{status.modalConfirm.content}}</p>
      <br>
    </Modal>
  </div>
</template>

<!--javascript 代码-->
<script>
  import ICol from "../../../node_modules/view-design/src/components/grid/col";
  import tiyData from "./js/list/order_data"
  import SendEmail from "../email/SendEmailTemplate.vue"
  import {
    init,
    webList,
    exportTransferExcel,
    prepareOrders,
    exportReport,
    clearSelectedOrders,
    confirmOrders,
    stockOutOrders,
    getUserContactInfo,
    batchExportOrdersBlank,
    batchExportOrdersInvoice,
    exportMiaozhangSale,
    exportPurchaseOrders,
    exportProductCodeForPrint,
    exportOrderTurnover,
    modifyImportantNote,
    exportTradeData
  } from "./js/list/order_funs"
  import Operation from "view-design/src/components/transfer/operation";
  import AOrderDetail from "../order/OrderDetail.vue"
  import KeyValueView from "../widgets/KeyValueView";
  import {isEmpty} from "../js/commonUtils";
  import ListSort from "../widgets/ListSort";


  export default {
    components: {Operation, ICol,AOrderDetail,SendEmail,KeyValueView,ListSort},
    data(){
      return {
        tRole:{//权限
          ORDER_1_101:"ORDER-1-101",
          ORDER_1_102:"ORDER-1-102",
          ORDER_1_103:"ORDER-1-103",
          ORDER_1_111:"ORDER-1-111",
          ORDER_1_112:"ORDER-1-112",
          ORDER_1_113:"ORDER-1-113",
          ORDER_1_221:"ORDER-1-221",
          ORDER_1_104:"ORDER-1-104",
          ORDER_1_105:"ORDER-1-105",
          ORDER_1_106:"ORDER-1-106",
          ORDER_1_107:"ORDER-1-107",
          ORDER_1_108:"ORDER-1-108",
          ORDER_1_109:"ORDER-1-109",
          ORDER_1_219: "ORDER-1-219",
          ORDER_1_110: "ORDER-1-110",
          ORDER_1_114: "ORDER-1-114",
          ORDER_1_115: "ORDER-1-115",
          COMMON_1_100:"COMMON-1-100"
        },
        openCollapse: "0",
        tPage: tiyData.tPage,
        status: tiyData.tStatus,
        //搜索条件
        params: tiyData.tParams,
        //字典 订单状态
        orderStateDict: this.$store.getters.dictionaries.orderStateDict,
        //字典 包裹状态
        packageStateDict: this.$store.getters.dictionaries.packageStateDict,
        //字典 订单子项状态
        orderItemStateDict: this.$store.getters.dictionaries.orderItemStateDict,
        //字典 支付方式
        payTypeDict: this.$store.getters.dictionaries.payTypeDict,
        //字典 快运公司
        deliverCompanyList: this.$store.getters.dictionaries.deliverCompanyList,
        //字典 配送方式
        postageMethodDict : this.$store.getters.dictionaries.postageMethodDict,
        yunPath: this.$store.getters.imgPrefix,
        tData: tiyData.tData,
        orderList: tiyData.tData.orderList,
        dateRange: tiyData.tData.dateRange,
        tableTitles:tiyData.tableTitles(this),
        check: '',
        isCheckedAllMessage: false,
        orderId:'',
        isShowDetail:tiyData.tStatus.modalDetail.isShow,
        showEmailState:{// 发送邮件相关的状态
          isShowing:false,
          selectedUsers:[// 测试数据
            {
              contactEmail:"545794510@qq.com.com",
              encodeName:"Jacqueline",
              fullEmail:" Vary"
            },
          ],
        },
        importantNote: "",
      }
    },
    computed : {

    },
    methods: {
      checkChange() {
        let length=0;
        this.orderList.forEach(item=>{
          if(!item._disabled){
            length++;
          }
        });
        if (this.params.selectedOrders.length == length) {
          this.isCheckedAllMessage = true;
        } else {
          this.isCheckedAllMessage = false;
        }
      },
      handleCheckAll() {
        let self = this;
        if (self.isCheckedAllMessage) {
          self.params.selectedOrders.splice(0, self.params.selectedOrders.length);
          for(let i=0;i<self.orderList.length;i++){
            if(!self.orderList[i]._disabled){
              self.params.selectedOrders.push(self.orderList[i]);
            }
          }
        } else {
          self.params.selectedOrders.splice(0, self.params.selectedOrders.length);
        }
      },
      isEmpty(val) {
        return isEmpty(val);
      },
      search(){
        tiyData.tPage.currentPage = 1;
        webList(this, tiyData);
      },
      changePage(page){
        tiyData.tPage.currentPage = page;
        webList(this, tiyData);
      },
      sizeChange(p){
        tiyData.tPage.stepNumber = p;
        webList(this, tiyData);
      },

      orderSelectedChanged(selection){
        tiyData.tParams.selectedOrders = selection;
      },

      checkSelectedOrderState(type){ //列表点击按钮前判断选中订单状态
        let ret = {"success" : true};
        if(tiyData.tParams.selectedOrders.length <= 0){
            ret.success = false;
            ret.error = "先选择订单！";
            return ret;
        }
        for(let i = 0; i < tiyData.tParams.selectedOrders.length; i++){
            let order = tiyData.tParams.selectedOrders[i];
            switch(type){
            case 1: //ems物流对接单、配货单
              if(order.state != 115  && order.state != 113 && order.state != 114){
                ret.success = false;
                ret.error = "只能导出“确认收款”、“备货”和“出库”状态的订单！";
                return ret;
              }
              break;
            case 2: //订单确认
              if(order.state != 110 && order.state != 116) {
                ret.success = false;
                ret.error = "只能对“已支付”和“待确认”状态的订单执行确认操作！";
              }
              break;
            case 3: //订单备货
              if(order.state != 115) {
                ret.success = false;
                ret.error = "只能对“已确认”状态的订单执行备货操作！";
              }
              break;
            case 4: //订单出库
              if(order.state != 113) {
                ret.success = false;
                ret.error = "只能对“备货”状态的订单执行出库操作！";
              }
              break;
            case 5: //发货单
                if(order.state < 111 || order.state > 115){
                    ret.success = false;
                    ret.error = "只能导出“确认收款”、“备货”、“出库”和“发货”状态的订单！";
                    return ret;
                }
                break;
            case 6: //秒帐销售单
                if(order.state <=110 || order.state == 116 || order.state == 120 || order.state == 121){
                    ret.success = false;
                    ret.error = "不能导出款项未到账和已退款的订单！";
                    return ret;
                }
                break;
            case 7: //跨境电商认证数据
                if(order.state != 100) {
                  ret.success = false;
                  ret.error = "不能导出款项未到账和已退款的订单！"
                }
                break;
            default :
              break;
          }
        }
        return ret;
      },
      exportTransferExcel(){
          let checked = this.checkSelectedOrderState(1);
          if(checked.success){
              exportTransferExcel(this, tiyData);
          } else {
            let self = this;
            this.$Modal.error({
              title: "error",
              content: checked.error,
              width:500,
              onOk : function(){
                clearSelectedOrders(self, tiyData);
              }
            });
          }
        },
      showPrepareModal(){
        let checked = this.checkSelectedOrderState(3);
        if(checked.success) {
            tiyData.tStatus.modalAction.title = "订单备货确认";
            tiyData.tStatus.modalAction.content = "确认备货已选中的订单";
            tiyData.tStatus.modalAction.type = 0;
            tiyData.tStatus.modalAction.isShow = true;
        }else{
            let self = this;
            this.$Modal.error({
                title: "error",
                content: checked.error,
                width:500,
                onOk : function(){
                    clearSelectedOrders(self, tiyData);
                }
            });

        }
      },
      showStockOutModal(){
          let checked = this.checkSelectedOrderState(4);
          if(checked.success){
              tiyData.tStatus.modalAction.title="订单出库确认";
              tiyData.tStatus.modalAction.content="确认出库已选中的订单吗";
              tiyData.tStatus.modalAction.type=1;
              tiyData.tStatus.modalAction.isShow=true;
          } else {
              let self = this;
              this.$Modal.error({
                  title: "error",
                  content: checked.error,
                  width:500,
                  onOk : function(){
                      clearSelectedOrders(self, tiyData);
                  }
              });
          }

      },
      showImportantNoteModal() {
        let checked = this.checkSelectedOrderState();
        if(checked.success) {
          this.params.modifyImportantNote.orderIds = tiyData.tParams.selectedOrders.map(obj => {return obj.id});
          this.params.modifyImportantNote.importantNote = "";
          // console.log(this.params.modifyImportantNote.orderIds);
          this.status.modalImportantNote.isShow = true;
        } else {
          let self = this;
          this.$Modal.error({
            title: "error",
            content: checked.error,
            width:500,
            onOk : function(){
              clearSelectedOrders(self, tiyData);
            }
          });
        }
      },
      clearImportantNote() {
        this.params.modifyImportantNote.importantNote = "";
      },
      modifyImportantNote() {
        // this.status.modalConfirm.title = "确认提示";
        // this.status.modalConfirm.content = "订单原来的重要说明会被覆盖，确认继续保存吗？";
        // let self = this;
        // this.status.modalConfirm.onOk = () => {
        //   modifyImportantNote(self, tiyData);
        // };
        // this.status.modalConfirm.isShow = true;
        modifyImportantNote(this, tiyData);
      },
      removeImportantNote() {
        let checked = this.checkSelectedOrderState();
        if(checked.success) {
          this.params.modifyImportantNote.orderIds = tiyData.tParams.selectedOrders.map(obj => {return obj.id});
          this.params.modifyImportantNote.importantNote = "";
          // console.log(this.params.modifyImportantNote.orderIds);
          this.status.modalConfirm.title = "确认提示";
          this.status.modalConfirm.content = "确定要清除所选订单的重要说明吗？";
          let self = this;
          this.status.modalConfirm.onOk = () => {
            modifyImportantNote(self, tiyData);
          };
          this.status.modalConfirm.isShow = true;
        } else {
          let self = this;
          this.$Modal.error({
            title: "error",
            content: checked.error,
            width:500,
            onOk : function(){
              clearSelectedOrders(self, tiyData);
            }
          });
        }
      },
      actionOk(){
        if(tiyData.tStatus.modalAction.type==0){//备货
          this.prepareOrders();
        }else if(tiyData.tStatus.modalAction.type==1){//出库
          this.stockOutOrders();
        }
      },
      prepareOrders(){
        let checked = this.checkSelectedOrderState(3);
        if(checked.success){
          prepareOrders(this, tiyData);
        } else {
          let self = this;
          this.$Modal.error({
            title: "error",
            content: checked.error,
            width:500,
            onOk : function(){
              clearSelectedOrders(self, tiyData);
            }
          });
        }
      },

      exportReport(){
        exportReport(this, tiyData);
      },

      showConfirmOrders(){ //显示确认订单对话框
        let checked = this.checkSelectedOrderState(2);
        if(checked.success){
          tiyData.tStatus.modalConfirmOrderShow = true;
          tiyData.tParams.isConfirmed=1
        } else {
          let self = this;
          this.$Modal.error({
            title: "error",
            content: checked.error,
            width:500,
            onOk : function(){
              clearSelectedOrders(self, tiyData);
            }
          });
        }
      },
      confirmOrders(){//确认订单
        confirmOrders(this, tiyData);
      },
      stockOutOrders(){//订单出库
        let checked = this.checkSelectedOrderState(4);
        if(checked.success){
          stockOutOrders(this, tiyData);
        } else {
          let self = this;
          this.$Modal.error({
            title: "error",
            content: checked.error,
            width:500,
            onOk : function(){
              clearSelectedOrders(self, tiyData);
            }
          });
        }
      },
      showRefundModal(){
        this.status.modalRefund.isShow = true;
      },
      showOrderDetail(id){
        this.orderId = id;
        this.isShowDetail = true;
      },
      hideDetail(){
          this.isShowDetail = false;
          this.orderId = "";
      },
      getDeviceName(deviceType){
        let device = '';
        switch(deviceType){
          case 1:
            device = 'Android';
            break;
          case 2:
            device = 'IOS';
            break;
          case 3:
            device = 'PC';
            break;
          case 4:
            device = 'Mobile PC';
            break;
          default:
            break;
        }
        return device;
      },
      showUserContactInfo(user){
        tiyData.tStatus.modalUserContactInfo.info.userName = user.userName;
        tiyData.tStatus.modalUserContactInfo.info.encodeName = user.encodeName;
        getUserContactInfo(this, tiyData, user.userId);
      },
      showEmail(){
        this.showEmailState.selectedUsers.length = 0;
        this.showEmailState.selectedUsers.push({
          contactEmail:tiyData.tStatus.modalUserContactInfo.info.email,
          encodeName:tiyData.tStatus.modalUserContactInfo.info.encodeName,

        });
        this.showEmailState.isShowing = true;
      },
      sendSuccess(isSuccess){
        if(isSuccess){
          this.showEmailState.isShowing = false;
        }
      },
      showInnerNote(orderId){
        let self=this;
        self.$ySpliceAll(self.tData.innerNoteList);
        let params={orderId:orderId};
          let hasNote = false;
          self.$apiOrder.getInnerNoteList(params).then(function (response) {
              if (response.success) {
                  let list=response.result;
                  if(list && list.length > 0){
                      hasNote = true;
                      list.forEach(function(item){
                          self.tData.innerNoteList.push(item);
                      });
                  }
              }
              if(hasNote){
                  self.status.modalInnerNote.isShow=true;
              } else {
                  self.$Message.error("此订单没有运营备注。");
              }
          });
      },
      orderSort(sortBy){
          tiyData.tPage.total = 1;
          tiyData.tPage.startIndex = 0;
          tiyData.tPage.currentPage = 1;
          tiyData.tParams.orderBy =sortBy;
          webList(this, tiyData);
      },
      batchExportOrdersBlank(){ //批量导出配货单
          let checked = this.checkSelectedOrderState(1);
          if(checked.success){
              batchExportOrdersBlank(this, tiyData);
          } else {
              let self = this;
              this.$Modal.error({
                  title: "error",
                  content: checked.error,
                  width:500,
                  onOk : function(){
                      clearSelectedOrders(self, tiyData);
                  }
              });
          }
      },
      batchExportOrdersInvoice(){ //批量导出发货单
          let checked = this.checkSelectedOrderState(5);
          if(checked.success){
              batchExportOrdersInvoice(this, tiyData);
          } else {
              let self = this;
              this.$Modal.error({
                  title: "error",
                  content: checked.error,
                  width:500,
                  onOk : function(){
                      clearSelectedOrders(self, tiyData);
                  }
              });
          }
      },
      exportMiaozhangSale(){ //导出秒帐销售单
          let checked = this.checkSelectedOrderState(6);
          if(checked.success){
              exportMiaozhangSale(this, tiyData);
          } else {
              let self = this;
              this.$Modal.error({
                  title: "error",
                  content: checked.error,
                  width:500,
                  onOk : function(){
                      clearSelectedOrders(self, tiyData);
                  }
              });
          }
      },
      exportPurchaseOrders() { //导出订单采购单
        let checked = this.checkSelectedOrderState(6);
        if (checked.success) {
          exportPurchaseOrders(this, tiyData);
        } else {
          let self = this;
          this.$Modal.error({
            title: "error",
            content: checked.error,
            width: 500,
            onOk: function () {
              clearSelectedOrders(self, tiyData);
            }
          });
        }
      },
      batchExportProductCodes() { //导出订单产品编码，用于打印
        let checked = this.checkSelectedOrderState(5);
        if (checked.success) {
          exportProductCodeForPrint(this, tiyData);
        } else {
          let self = this;
          this.$Modal.error({
            title: "error",
            content: checked.error,
            width: 500,
            onOk: function () {
              clearSelectedOrders(self, tiyData);
            }
          });
        }
      },
      exportOrderTurnover() {
        exportOrderTurnover(this, tiyData);
      },
      showExportTransferExcel() {
        tiyData.tStatus.modalExportTransferExcel.isShow = true;
        tiyData.tParams.transferExcelType = 3;
      },
      copyEmail(email){
          let oInput = document.createElement('input');
          oInput.value = email;
          document.body.appendChild(oInput);
          oInput.select(); // 选择对象
          document.execCommand("Copy"); // 执行浏览器复制命令
          oInput.className = 'oInput';
          oInput.style.display = 'none';
          this.$Message.success('邮箱地址已复制');
      },
      batchExportTradeData() {
        let checked = this.checkSelectedOrderState(7);
        exportTradeData(tiyData, this);
      }
    },
    mounted(){
      init(this, tiyData);
      // webList(this, tiyData);
    }
  }
</script>

<!--css样式-->
<style scoped lang="less">
@import  (once,optional)  "../css/base.less";

  .table_css {
    margin: 1rem 0px;
  }

  .modal_newuser_form {
    padding-left: 60px;
    padding-top: 30px;
    padding-bottom: 30px;
  }

  .modal_form_input {
    width: 140px;
    margin-right: 10px;

  }

  .order_product_div {
    margin-top: 1rem;

  }
  .order_product_row {
    background: #f3f3f6;
    padding: 1rem;
    border: .0625rem solid #dbdbdb;
    border-bottom-style: none;
  }

  .key{
   .tiy_key;
  }

  .order_btns{
    button{
      margin-bottom: 0.5rem;
    }
  }
  .confirm-dialog {
    z-index: 1001;
  }

.list_item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.list_item:hover {
  background: @tiySectionColor;
}
</style>
